# -*-codeing = utf-8 -*-
# @Tine:2024/9/19 
# @Author:计科201121尚益帆
# File：4.5.py
# @Software:PyCharm

import random

def detstudent(students, num):
    # 删除指定行
    del students[num]
    print(students)
    # 将修改后的内容写回文件
    with open("day3\\学生名单1（原始）.txt", "w", encoding='utf-8') as file1:
         file1.writelines(students)

with open("day3\\学生名单1（原始）.txt", "r", encoding='utf-8') as file:
    # 获取所有行信息，返回列表存储
    students = file.readlines()
    # 随机抽取一名学生
    num = random.randint(0,len(students)-1)
    print(students[num])
    # 放入新的文件
    with open("day3\\学生名单1（新）.txt", "a", encoding='utf-8') as f:
        f.write(students[num])

    # 删除学生
    detstudent(students, num)